<script type="text/javascript">
/* eslint-disable */
// 编辑器对象
let editor;
// 编辑器初始代码
let defaultCode =
  '# version: Python3\n' +
  '# please edit your code here:\n' +
  'import turtle\n' +
  'print(\'hello1\')\n' +
  't = turtle.Turtle()\n' +
  't.color(\'red\')\n' +
  't.forward(75)\n' +
  '# code end\n';
// CodeMirror配置
const config = {
  mode: 'python',
  lineNumbers: true,
  keyMap: 'sublime',            // 快键键风格
  smartIndent: true,            // 智能缩进
  indentUnit: 4,                // 缩进单位2个空格
  indentWithTabs: true,         // 使用制表符进行智能缩进
  lineWrapping: true,           //
  gutters: [
    'CodeMirror-linenumbers',
    'CodeMirror-foldgutter',
    'CodeMirror-lint-markers'
  ],                            // 括号匹配
  // foldGutter: true,          // 启用行槽中的代码折叠
  autofocus: true,              // 自动聚焦
  matchBrackets: true,          // 匹配结束符号，比如"]、}"
  autoCloseBrackets: true,      // 自动闭合符号
  styleActiveLine: true         // 显示选中行的样式
}

function setEditor (canvas) {
  // 设置Canvas
  let textArea = document.getElementById(canvas);
  editor = CodeMirror.fromTextArea(textArea, config)
  editor.setSize('100%', '100%');
  return editor;
}
function getEditor() {
  return editor;
}
function getDefaultCode() {
  return defaultCode;
}
function setDefaultCode() {
  // defaultCode = text;
  CodeMirror.Hi
}

  // 暴露出这些属性和方法
  export default {
    setEditor,
    getEditor,
    getDefaultCode,
    setDefaultCode
  }
</script>